<?php

namespace App\Common\Tools;

use EasyWeChat\Factory;
use Carbon\Carbon;
use App\Models\User;


class Push
{
    private $app;

    public function __construct()
    {
        $this->app = Factory::miniProgram(config('wechat.mini_program.default'));
    }


    public function send( $template, $user_id , $data)
    {
        if ($template == "认证结果通知") {
            $user = User::where('id', $user_id)
                ->first();
            $template_id = '0Dh_t66fttKdkGUvjTZEwDRWsDo5RgaZN3WXyQrLc9k';
            $data = [
                'template_id' => $template_id, // 所需下发的订阅模板id
                'touser' => $user->open_id,     // 接收者（用户）的 openid
                'page' => '',       // 点击模板卡片后的跳转页面，仅限本小程序内的页面。支持带参数,（示例index?foo=bar）。该字段不填则模板无跳转。
                'data' => [         // 模板内容，格式形如 { "key1": { "value": any }, "key2": { "value": any } }
                    'thing1' => [
                        'value' => $data['thing1'],//绑定手机通知
                    ],
                    'phrase2' => [
                        'value' => $data['phrase2'],//通过
                    ],
                    'thing3' => [
                        'value' => $data['thing3'],//恭喜,绑定手机成功
                    ],
                ],
            ];

        }

        $res = $this->app->subscribe_message->send($data);

        return $res;




    }

}
